/**
 * 获取文件对应的svg图标指令
 * 使用方式 v-fileSvg="fileName"
 * 如果需要指定文件名字使用 v-fileSvg="["fileName", "fileSize"]"
 * @Prop fileName 文件名
 * @Prop fileSize svg大小，默认30
 */
import Vue from 'vue'
/**
 * 获取对应文件svg图标
 * @param fileName
 * @param size
 * @returns
 */
const getFileSvg = (fileName: string, size: number) => {
  size = size || 30
  let fileType: any = fileName.split('.').pop()?.toLowerCase()
  const type: any = {
    doc: 'word',
    docx: 'word',
    xls: 'excel',
    xlsx: 'excel',
    pdf: 'pdf',
    ppt: 'ppt',
    pptx: 'ppt',
    png: 'image',
    jpeg: 'image',
    jpg: 'image',
    gif: 'image',
    svg: 'image',
    mp4: 'video',
    avi: 'video',
    flv: 'video',
    mp3: 'mp3',
    txt: 'txt',
    zip: 'zip',
    bmp: 'image',
    wave: 'mp3',
    mpeg: 'video'
  }
  fileType = type[fileType] ? type[fileType] : 'other'
  switch (fileType) {
    case 'word':
      return `<svg t="1634809110510" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3107" width="${size}" height="${size}"><path d="M658.78 64.39H269.46c-78.06 0-141.33 63.28-141.33 141.33v612.95c0 78.06 63.28 141.33 141.33 141.33h485.49c78.06 0 141.33-63.28 141.33-141.33V301.88c0-31.83-12.64-62.35-35.15-84.85l-117.5-117.5a120.008 120.008 0 0 0-84.85-35.14z" fill="#53B7F4" p-id="3108"></path><path d="M647.85 360.65c-13.25 0-24 10.75-24 24v226.26l-94.35-93.29c-9.33-9.22-24.34-9.25-33.69-0.05l-95.26 93.6V383.99c0-13.25-10.75-24-24-24s-24 10.75-24 24V668.4c0 9.67 5.8 18.39 14.72 22.13a24.002 24.002 0 0 0 26.1-5.01L512.58 568.4l118.4 117.07a23.993 23.993 0 0 0 16.88 6.93c3.11 0 6.25-0.61 9.24-1.85a24 24 0 0 0 14.75-22.15V384.65c0-13.25-10.74-24-24-24zM861.13 217.03l-117.5-117.5a120.001 120.001 0 0 0-61.75-32.9v131.88c0 41.87 33.94 75.81 75.81 75.81h135.37a119.975 119.975 0 0 0-31.93-57.29z" fill="#29A3D3" p-id="3109"></path><path d="M647.86 680.4c-6.2 0-12.3-2.4-16.88-6.93L512.58 556.4 393.37 673.52a23.99 23.99 0 0 1-26.1 5.01 23.992 23.992 0 0 1-14.72-22.13V371.99c0-13.25 10.75-24 24-24s24 10.75 24 24v227.19l95.26-93.6c9.36-9.19 24.37-9.17 33.69 0.05l94.35 93.29V372.65c0-13.25 10.75-24 24-24s24 10.75 24 24V656.4c0 9.68-5.82 18.42-14.75 22.15a24.112 24.112 0 0 1-9.24 1.85z" fill="#FFFFFF" p-id="3110"></path></svg>`
    case 'video':
      return `<svg t="1637145326429" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8211" width="${size}" height="${size}"><path d="M667.51696244 65.11217689v136.03265336a77.57972607 77.57972607 0 0 0 73.82586838 77.57972608h159.44957529v602.40478556A77.57972607 77.57972607 0 0 1 823.03392487 958.88782311H200.96607513a77.57972607 77.57972607 0 0 1-77.75848124-77.75848122v-738.25868378A77.57972607 77.57972607 0 0 1 200.96607513 65.11217689z" fill="#CD62FF" p-id="8212"></path><path d="M667.51696244 65.11217689l116.54834426 106.8955673 116.72709941 106.8955673h-155.51696244a77.75848124 77.75848124 0 0 1-77.75848123-77.75848124z m0 0" fill="#EFA3FF" p-id="8213"></path><path d="M431.73894698 453.904583l207.35594991 119.58718145a14.65792061 14.65792061 0 0 1 7.32896032 12.51285906 14.47916546 14.47916546 0 0 1-7.32896032 12.51285905l-207.35594991 119.58718147a14.65792061 14.65792061 0 0 1-21.98688091-12.51285906V466.41744206a14.47916546 14.47916546 0 0 1 7.32896031-12.51285906 14.83667573 14.83667573 0 0 1 14.6579206 0z m0 0" fill="#FFFFFF" p-id="8214"></path></svg>`
    case 'mp3':
      return `<svg t="1634806563533" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7675" width="${size}" height="${size}"><path d="M667.51696244 65.11217689v136.03265336a77.57972607 77.57972607 0 0 0 73.82586838 77.57972608h159.44957529v602.40478556A77.57972607 77.57972607 0 0 1 823.03392487 958.88782311H200.96607513a77.57972607 77.57972607 0 0 1-77.75848124-77.75848122v-738.25868378A77.57972607 77.57972607 0 0 1 200.96607513 65.11217689z" fill="#17B490" p-id="7676"></path><path d="M667.51696244 65.11217689l116.54834426 106.8955673 116.72709941 106.8955673h-155.51696244a77.75848124 77.75848124 0 0 1-77.75848123-77.75848124z m0 0" fill="#5EE0BA" p-id="7677"></path><path d="M616.5717506 434.59902902l-149.97555343 39.6836387c-17.69675779 5.18389874-33.60596429 20.735595-33.6059643 36.28729126v137.99895975s-11.97659365-6.61393978-35.39351559-3.39634743c-33.60596429 5.18389874-63.10056062 29.49459633-63.10056062 55.23533493s29.67335146 39.68363869 64.88811192 36.28729125 61.13425421-27.70704502 61.13425419-51.83898751v-132.99381614c0-10.36779749 15.9092065-15.55169626 15.90920651-15.55169624l132.45755075-35.92978098s13.76414495-3.39634746 13.76414498 6.7926949v110.64942502s-13.76414495-6.79269492-37.35982201-3.39634747c-35.57227072 3.39634746-65.06686705 27.70704502-65.06686705 51.83898745s29.85210659 41.29243487 65.06686705 37.89608743 64.8881119-27.70704502 64.8881119-51.83898749V455.33462404c0-15.55169626-15.9092065-25.7407386-33.6059643-20.73559502z m0 0" fill="#FFFFFF" p-id="7678"></path></svg>`
    case 'excel':
      return `<svg t="1635330971900" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8621" width="${size}" height="${size}"><path d="M667.51696244 65.11217689v136.03265336a77.57972607 77.57972607 0 0 0 73.82586838 77.57972608h159.44957529v602.40478556A77.57972607 77.57972607 0 0 1 823.03392487 958.88782311H200.96607513a77.57972607 77.57972607 0 0 1-77.75848124-77.75848122v-738.25868378A77.57972607 77.57972607 0 0 1 200.96607513 65.11217689z" fill="#67BA33" p-id="8622"></path><path d="M667.51696244 65.11217689l116.54834426 106.8955673 116.72709941 106.8955673h-155.51696244a77.75848124 77.75848124 0 0 1-77.75848123-77.75848124z m0 0" fill="#9AD370" p-id="8623"></path><path d="M477.67901519 588.86470558l-101.17540315-129.59746872h69.89325553l66.31815294 92.77391208 69.35699017-92.77391208h67.74819398L546.32098481 588.86470558l108.68311859 137.82020465h-70.78703118l-72.93209273-98.13656596-73.11084785 98.85158647H368.9958966z m0 0" fill="#FFFFFF" p-id="8624"></path></svg>`
    case 'ppt':
      return `<svg t="1635330986461" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8765" width="${size}" height="${size}"><path d="M667.51696244 65.11217689v136.03265336a77.57972607 77.57972607 0 0 0 73.82586838 77.57972608h159.44957529v602.40478556A77.57972607 77.57972607 0 0 1 823.03392487 958.88782311H200.96607513a77.57972607 77.57972607 0 0 1-77.75848124-77.75848122v-738.25868378A77.57972607 77.57972607 0 0 1 200.96607513 65.11217689z" fill="#F6913F" p-id="8766"></path><path d="M667.51696244 65.11217689l116.54834426 106.8955673 116.72709941 106.8955673h-155.51696244a77.75848124 77.75848124 0 0 1-77.75848123-77.75848124z m0 0" fill="#F9B77F" p-id="8767"></path><path d="M377.93365306 459.26723686h175.53753691c70.2507658 0 92.59515694 40.21990407 92.59515697 83.29989024s-27.88580015 82.40611457-91.70138132 82.40611457h-116.54834425v102.42668907H377.93365306z m59.88296831 124.05605969h96.52776978c34.32098481 0 52.73276314-8.75900132 52.73276313-40.21990408s-24.84696295-40.93492461-47.90637464-40.93492458h-101.35415827z m0 0" fill="#FFFFFF" p-id="8768"></path></svg>`
    case 'pdf':
      return `<svg t="1635330692747" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8333" width="${size}" height="${size}"><path d="M667.51696244 65.11217689v136.03265336a77.57972607 77.57972607 0 0 0 73.82586838 77.57972608h159.44957529v602.40478556A77.57972607 77.57972607 0 0 1 823.03392487 958.88782311H200.96607513a77.57972607 77.57972607 0 0 1-77.75848124-77.75848122v-738.25868378A77.57972607 77.57972607 0 0 1 200.96607513 65.11217689z" fill="#FF6262" p-id="8334"></path><path d="M667.51696244 65.11217689l116.54834426 106.8955673 116.72709941 106.8955673h-155.51696244a77.75848124 77.75848124 0 0 1-77.75848123-77.75848124z m0 0" fill="#FFA3A3" p-id="8335"></path><path d="M642.84875461 615.3204647c-6.79269492-7.32896029-18.76928857-11.26157314-35.75102585-11.79783853a246.50332321 246.50332321 0 0 0-46.65508873 5.18389875 224.69519748 224.69519748 0 0 1-45.04629257-57.91666186c12.51285904-41.11367972 13.58538981-70.42952092 3.21759232-84.55117614a26.63451427 26.63451427 0 0 0-20.735595-10.54655263 25.91949376 25.91949376 0 0 0-24.84696295 12.87036932c-13.76414495 22.88065653 5.18389874 66.85441833 14.47916549 85.44495177a527.86389665 527.86389665 0 0 1-38.9686182 90.98636078c-73.289603 31.63965788-73.289603 51.12396697-73.28960301 57.38039647a23.95318731 23.95318731 0 0 0 13.58538985 21.80812577 21.4506155 21.4506155 0 0 0 12.15534879 3.21759234c19.66306421 0 41.47118997-20.91435011 65.06686704-62.38554011a551.28081858 551.28081858 0 0 1 87.41125818-27.88580016 97.77905571 97.77905571 0 0 0 55.95035547 22.34439116c12.69161419 0 39.1473733 0 39.14737329-26.99202452a22.16563603 22.16563603 0 0 0-5.72016412-17.16049241z m-20.91435014 17.33924752a33.06969892 33.06969892 0 0 1-12.33410389 0.89377566 67.92694909 67.92694909 0 0 1-16.44547191-3.5751026c4.46887824-0.35751025 8.5802462-0.35751025 13.22787959-0.35751024 10.01028723 0 14.12165522 1.60879617 15.55169621 3.03883718z m-92.59515693-8.0439808a414.71189985 414.71189985 0 0 0-45.58255796 13.40663471v-0.89377566c7.15020517-14.65792061 13.94290009-29.85210659 19.84181935-45.04629257l0.71502051 0.71502051 0.35751027-1.07253077a214.68491023 214.68491023 0 0 0 25.56198347 31.28214761h-2.5025718z m-33.78471942-142.82534828h2.32381666a61.31300932 61.31300932 0 0 1 0.35751027 31.63965788 56.84413109 56.84413109 0 0 1-2.68132693-31.63965788z m-74.18337865 204.85337814a45.2250477 45.2250477 0 0 1-16.62422702 13.40663468 57.73790673 57.73790673 0 0 1 16.62422702-13.40663468z" fill="#FFFFFF" p-id="8336"></path></svg>`
    case 'image':
      return `<svg t="1637200284906" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8273" width="${size}" height="${size}"><path d="M667.51696244 65.11217689v136.03265336a77.57972607 77.57972607 0 0 0 73.82586838 77.57972608h159.44957529v602.40478556A77.57972607 77.57972607 0 0 1 823.03392487 958.88782311H200.96607513a77.57972607 77.57972607 0 0 1-77.75848124-77.75848122v-738.25868378A77.57972607 77.57972607 0 0 1 200.96607513 65.11217689z" fill="#008BEE" p-id="8274"></path><path d="M667.51696244 65.11217689l116.54834426 106.8955673 116.72709941 106.8955673h-155.51696244a77.75848124 77.75848124 0 0 1-77.75848123-77.75848124z m0 0" fill="#53B3F7" p-id="8275"></path><path d="M449.0781945 459.26723686a47.19135413 47.19135413 0 1 1-46.65508872 47.19135414 46.83384387 46.83384387 0 0 1 46.65508872-47.19135414z m-71.68080682 268.13269388a14.30041034 14.30041034 0 0 1-9.29526672-3.39634744 14.83667573 14.83667573 0 0 1-1.60879617-20.55683988l65.9606427-100.28162752a14.30041034 14.30041034 0 0 1 19.48430909-2.14506155l58.09541699 43.61625155 104.39299549-119.58718145c4.82638849-6.25642953 31.10339247-35.75102585 46.47633361-2.3238167v204.67462299c-0.17875514-0.17875514-283.32687985 0-283.50563499 0z m0 0" fill="#FFFFFF" p-id="8276"></path></svg>`
    case 'txt':
      return `<svg t="1634809310752" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5263" width="${size}" height="${size}"><path d="M659.72 64.19H270.4c-78.06 0-141.33 63.28-141.33 141.33v612.95c0 78.06 63.28 141.33 141.33 141.33h485.49c78.06 0 141.33-63.28 141.33-141.33V301.69c0-31.83-12.64-62.35-35.15-84.85l-117.5-117.5a120.017 120.017 0 0 0-84.85-35.15z" fill="#4FD397" p-id="5264"></path><path d="M862.07 216.84l-117.5-117.5a120.001 120.001 0 0 0-61.75-32.9v131.88c0 41.87 33.94 75.81 75.81 75.81H894a119.975 119.975 0 0 0-31.93-57.29zM670.25 381.88H517.97a24.052 24.052 0 0 0-9.66 0H356.03c-13.25 0-24 10.75-24 24s10.75 24 24 24h133.11v258.73c0 13.25 10.75 24 24 24s24-10.75 24-24V429.88h133.11c13.25 0 24-10.75 24-24s-10.75-24-24-24z" fill="#19BC6E" p-id="5265"></path><path d="M670.25 369.88H517.97a24.052 24.052 0 0 0-9.66 0H356.03c-13.25 0-24 10.75-24 24s10.75 24 24 24h133.11v258.73c0 13.25 10.75 24 24 24s24-10.75 24-24V417.88h133.11c13.25 0 24-10.75 24-24s-10.75-24-24-24z" fill="#FFFFFF" p-id="5266"></path></svg>`
    case 'zip':
      return `<svg t="1634809702487" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5420" width="${size}" height="${size}"><path d="M659.72 64.81H270.4c-78.06 0-141.33 63.28-141.33 141.33v612.95c0 78.06 63.28 141.33 141.33 141.33h485.49c78.06 0 141.33-63.28 141.33-141.33V302.3c0-31.83-12.64-62.35-35.15-84.85l-117.5-117.5a120.008 120.008 0 0 0-84.85-35.14z" fill="#FFC757" p-id="5421"></path><path d="M304.85 196.81h71.52c7.86 0 14.24-6.38 14.24-14.24v-71.52c0-7.87-6.38-14.24-14.24-14.24h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.86 6.38 14.24 14.24 14.24zM476.37 196.81h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.87 6.38 14.24 14.24 14.24h71.52c7.86 0 14.24-6.38 14.24-14.24v-71.52c0-7.86-6.38-14.24-14.24-14.24zM304.85 396.81h71.52c7.86 0 14.24-6.38 14.24-14.24v-71.52c0-7.87-6.38-14.24-14.24-14.24h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.86 6.38 14.24 14.24 14.24zM476.37 396.81h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.87 6.38 14.24 14.24 14.24h71.52c7.86 0 14.24-6.38 14.24-14.24v-71.52c0-7.86-6.38-14.24-14.24-14.24zM455.65 552.02H321.52c-17.07 0-30.91 13.84-30.91 30.91v155.48c0 17.07 13.84 30.91 30.91 30.91h134.13c17.07 0 30.91-13.84 30.91-30.91V582.93c0-17.07-13.84-30.91-30.91-30.91z m-4.93 164.59c0 13.72-11.12 24.84-24.84 24.84h-74.6c-13.72 0-24.84-11.12-24.84-24.84v-27.36c0-13.72 11.12-24.84 24.84-24.84h74.6c13.72 0 24.84 11.12 24.84 24.84v27.36zM862.07 217.45l-117.5-117.5a120.001 120.001 0 0 0-61.75-32.9v131.88c0 41.87 33.94 75.81 75.81 75.81H894a120.021 120.021 0 0 0-31.93-57.29z" fill="#F79F2B" p-id="5422"></path><path d="M304.85 184.81h71.52c7.86 0 14.24-6.38 14.24-14.24V99.05c0-7.87-6.38-14.24-14.24-14.24h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.86 6.38 14.24 14.24 14.24zM476.37 184.81h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.87 6.38 14.24 14.24 14.24h71.52c7.86 0 14.24-6.38 14.24-14.24v-71.52c0-7.86-6.38-14.24-14.24-14.24zM304.85 384.81h71.52c7.86 0 14.24-6.38 14.24-14.24v-71.52c0-7.87-6.38-14.24-14.24-14.24h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.86 6.38 14.24 14.24 14.24zM476.37 384.81h-71.52c-7.86 0-14.24 6.38-14.24 14.24v71.52c0 7.87 6.38 14.24 14.24 14.24h71.52c7.86 0 14.24-6.38 14.24-14.24v-71.52c0-7.86-6.38-14.24-14.24-14.24zM455.65 540.02H321.52c-17.07 0-30.91 13.84-30.91 30.91v155.48c0 17.07 13.84 30.91 30.91 30.91h134.13c17.07 0 30.91-13.84 30.91-30.91V570.93c0-17.07-13.84-30.91-30.91-30.91z m-4.93 164.59c0 13.72-11.12 24.84-24.84 24.84h-74.6c-13.72 0-24.84-11.12-24.84-24.84v-27.36c0-13.72 11.12-24.84 24.84-24.84h74.6c13.72 0 24.84 11.12 24.84 24.84v27.36z" fill="#FFFFFF" p-id="5423"></path></svg>`
    default:
      return `<svg t="1634804787186" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7531" width="${size}" height="${size}"><path d="M667.51696244 65.11217689v136.03265336a77.57972607 77.57972607 0 0 0 73.82586838 77.57972608h159.44957529v602.40478556A77.57972607 77.57972607 0 0 1 823.03392487 958.88782311H200.96607513a77.57972607 77.57972607 0 0 1-77.75848124-77.75848122v-738.25868378A77.57972607 77.57972607 0 0 1 200.96607513 65.11217689z" fill="#008BEE" p-id="7532"></path><path d="M667.51696244 65.11217689l116.54834426 106.8955673 116.72709941 106.8955673h-155.51696244a77.75848124 77.75848124 0 0 1-77.75848123-77.75848124z m0 0" fill="#53B3F7" p-id="7533"></path><path d="M292.84621154 470.88632028h250.43593608v57.20164135H292.84621154zM292.84621154 663.94185985h375.56452653v57.20164137H292.84621154z" fill="#FFFFFF" p-id="7534"></path></svg>`
  }
}
const fun = (el, binding) => {
  let fileName = ''
  let fileSize = 30
  if (typeof binding.value === 'string') {
    fileName = binding.value
  } else if (Array.isArray(binding.value)) {
    [fileName, fileSize] = binding.value
  } else {
    console.warn('error params')
    return
  }
  if (!fileName) {
    return
  }
  // console.info(`🔉:使用指令插入文件svg[${fileName}]`)
  el.innerHTML = getFileSvg(fileName, fileSize)
}

const fileSvgDriective = {
  bind: fun,
  update: fun
}

Vue.directive('fileSvg', fileSvgDriective)
